package cn.openea.perpartner.wxpay.rabbit.service;


import cn.openea.perpartner.wxpay.entity.PayOrder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @author Weird077
 * @description TODO
 * @date 2023-02-07 16:23
 */
@Slf4j
@Service
public class PublisherService {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 延时队列交换机
     */
    @Value("${rabbit.business.exchange}")
    private String BUSINESS_EXCHANGE;
    /**
     * 业务队列路由键
     */
    @Value("${rabbit.business.routing_key}")
    private String BUSINESS_ROUTE_KEY;



    /**
     * 发送业务消息
     * @param order
     */
    public boolean execute(PayOrder order) {
        if (order== null || ObjectUtils.isEmpty(order)) {
            return false;
        }
        JSONObject object = (JSONObject) JSON.toJSON(order);
        rabbitTemplate.convertAndSend(BUSINESS_EXCHANGE, BUSINESS_ROUTE_KEY, object);
        return true;
    }
}
